﻿using AutoMapper;
using Domain.Entity;
using Domain.Entity.ord;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.SaleReturn_hService
{
    public class SaleReturn_hService : ISaleReturn_hService
    {
        private readonly ISaleReturn_hRepository saleReturn_HRepository;
        private readonly IMapper mapper;

        public SaleReturn_hService(ISaleReturn_hRepository saleReturn_HRepository,IMapper mapper)
        {
            this.saleReturn_HRepository = saleReturn_HRepository;
            this.mapper = mapper;
        }

        //添加
        public async Task<int> AddSaleReturn_h(AddSaleReturn_hDto addSaleReturn_HDto)
        {
            SaleReturn_h saleReturn_H=mapper.Map<SaleReturn_h>(addSaleReturn_HDto);
            return await saleReturn_HRepository.AddSaleReturn_h(saleReturn_H);
        }

        //审核
        public async Task<int> ApproverSaleReturn_h(int saletid, int status, string approvername, string approvertime)
        {
            return await saleReturn_HRepository.ApproverSaleReturn_h(saletid, status, approvername, approvertime);
        }


        //删除
        public async Task<int> DeleteSaleReturn_h(int id)
        {
            return await saleReturn_HRepository.DeleteSaleReturn_h(id);
        }


        //高级查询
        public async Task<FenYe<SaleReturn_h>> GetAdvancedSaleReturn_h(FenYe<SaleReturn_h> fenYe, string? code, string? starttotal, string? endtotal, string? startdate, string? enddate, string? startnum, string? endnum, int? status, int? cust, string? custlink, string? salecode, int? dep, int? user, string? createname, string? startcreatetime, string? endcreatetime, string? approvername, string? startapprovertime, string? endapprovertime)
        {
            return await saleReturn_HRepository.GetAdvancedSaleReturn_h(fenYe, code, starttotal, endtotal, startdate, enddate, startnum, endnum, status, cust, custlink, salecode, dep, user, createname, startcreatetime, endcreatetime, approvername, startapprovertime, endapprovertime);
        }


        //查询所有单据
        public async Task<List<SaleReturn_h>> GetAllSaleReturn_h()
        {
            return await saleReturn_HRepository.GetAllSaleReturn_h();
        }


        //分页查询
        public async Task<FenYe<SaleReturn_h>> GetSaleReturn_h(FenYe<SaleReturn_h> fenYe, string? code, int? status, int? cust, string? starttime, string? endtime)
        {
            return await saleReturn_HRepository.GetSaleReturn_h(fenYe,code,status,cust,starttime,endtime);
        }


        //根据编号查询信息
        public async Task<SaleReturn_h> GetSaleReturn_hByCode(string code)
        {
            return await saleReturn_HRepository.GetSaleReturn_hByCode(code);
        }


        //根据id查询信息
        public async Task<SaleReturn_h> GetSaleReturn_hById(int saletid)
        {
            return await saleReturn_HRepository.GetSaleReturn_hById(saletid);
        }


        //根据关联单号查询退货记录
        public async Task<List<SaleReturn_h>> GetSaleReturn_hs(string salecode)
        {
            return await saleReturn_HRepository.GetSaleReturn_hs(salecode);
        }


        //更新入库数量和状态
        public async Task<int> UpdateNum(int saletid, int oknum, int nonum, int statu)
        {
            return await saleReturn_HRepository.UpdateNum(saletid, oknum, nonum, statu);
        }


        //修改
        public async Task<int> UpdateSaleReturn_h(UpdateSaleReturn_hDto updateSaleReturn_HDto)
        {
            SaleReturn_h saleReturn_H=mapper.Map<SaleReturn_h>(updateSaleReturn_HDto);
            return await saleReturn_HRepository.UpdateSaleReturn_h(saleReturn_H);
        }


        //撤销
        public async Task<int> UpdateStatus(int saletid, int status)
        {
            return await saleReturn_HRepository.UpdateStatus(saletid, status);
        }
    }
}
